{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 解读 `Source`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## `SourceNode` \n",
    "\n",
    "```c++\n",
    "\n",
    "/*! \\brief A program source in any language.\n",
    " *\n",
    " * Could represent the source from an ML framework or a source\n",
    " * representing a tvm::IRModule.\n",
    " */\n",
    "class Source;\n",
    "\n",
    "class SourceNode : public Object {\n",
    " public:\n",
    "  /*! \\brief The source name. */\n",
    "  SourceName source_name;\n",
    "\n",
    "  /*! \\brief The raw source. */\n",
    "  String source;\n",
    "\n",
    "  /*! \\brief A mapping of line breaks into the raw source. */\n",
    "  std::vector<std::pair<int, int>> line_map;\n",
    "\n",
    "  // override attr visitor\n",
    "  void VisitAttrs(AttrVisitor* v) {\n",
    "    v->Visit(\"source_name\", &source_name);\n",
    "    v->Visit(\"source\", &source);\n",
    "  }\n",
    "\n",
    "  static constexpr const char* _type_key = \"Source\";\n",
    "  TVM_DECLARE_FINAL_OBJECT_INFO(SourceNode, Object);\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`SourceNode` 继承自 `Object` 类的子类，它表示程序源代码。该类具有以下成员变量和成员函数：\n",
    "\n",
    "- `source_name`：`SourceName` 类型的成员变量，表示源名称。\n",
    "- `source`：`String` 类型的成员变量，表示原始源代码。\n",
    "- `line_map`：`std::vector<std::pair<int, int>>` 类型的成员变量，表示行映射，将行号映射到原始源代码中的字符位置。\n",
    "- `VisitAttrs(AttrVisitor* v)`：一个成员函数，用于访问属性。它接受一个指向`AttrVisitor`对象的指针作为参数，并依次调用`v->Visit(\"source_name\", &source_name)`、`v->Visit(\"source\", &source)`来访问相应的属性。\n",
    "- `_type_key`：一个静态常量字符指针，表示该类型的键。\n",
    "- `TVM_DECLARE_FINAL_OBJECT_INFO(SourceNode, Object)`：一个宏定义，用于声明`SourceNode`对象的最终信息。\n",
    "\n",
    "总体来说，这段代码定义了一个表示程序源代码的类，并提供了相应的属性访问功能。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## `Source`\n",
    "\n",
    "```c++\n",
    "class Source : public ObjectRef {\n",
    " public:\n",
    "  TVM_DLL Source(SourceName src_name, std::string source);\n",
    "  TVM_DLL tvm::String GetLine(int line);\n",
    "\n",
    "  TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Source, ObjectRef, SourceNode);\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Source` 类继承自 `ObjectRef` 类。该类具有以下成员函数：\n",
    "\n",
    "- `Source(SourceName src_name, std::string source)`：一个构造函数，用于创建一个`Source`对象。它接受两个参数：`src_name`表示源名称，`source`表示源代码字符串。\n",
    "- `GetLine(int line)`：一个成员函数，用于获取指定行号的源代码内容。它接受一个整数类型的参数`line`，表示要获取的行号，并返回一个`tvm::String`类型的结果，表示该行的源代码内容。\n",
    "- `TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(Source, ObjectRef, SourceNode)`：一个宏定义，用于定义`Source`对象的非空引用方法。\n",
    "\n",
    "总体来说，这段代码定义了一个用于表示程序源代码的类，并提供了相应的构造函数和获取指定行源代码的功能。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "xin",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
